//
//  TBWelcomeViewController.swift
//  新浪微博
//
//  Created by bin on 16/1/29.
//  Copyright © 2016年 XMG. All rights reserved.
//

import UIKit
import SDWebImage

class TBWelcomeViewController: UIViewController {

    @IBOutlet weak var profileImageView: UIImageView!
    @IBOutlet weak var textLabel: UILabel!
    @IBOutlet weak var bottomCons: NSLayoutConstraint!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let userAccount = TBUserAccount.loadFormFile()
        let url = NSURL(string: (userAccount?.profile_image_url)!)
        textLabel.text = (userAccount?.screen_name)!  + " 欢迎回来"
        profileImageView.sd_setImageWithURL(url)
        setupAni()
        // Do any additional setup aft)er loading the view.
    }
    
    private func setupAni(){
        let profileImageViewH = profileImageView.bounds.size.height
        profileImageView.layer.cornerRadius = profileImageViewH * 0.5
        profileImageView.layer.masksToBounds = true
        textLabel.alpha = 0
        
        let bottomValue = ScreenH - 100 - profileImageViewH
        bottomCons.constant = bottomValue
        
        UIView.animateWithDuration(1.0, delay: 0.5, options: UIViewAnimationOptions(rawValue: 0), animations: { () -> Void in
            self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
                UIView.animateWithDuration(1, animations: { () -> Void in
                    self.textLabel.alpha = 1
                    }, completion: { (_) -> Void in
                        
                        NSNotificationCenter.defaultCenter().postNotificationName(SwitchRootViewControllerNotification, object: self, userInfo: ["vc" : "main"])
                })
        }
    }

    

}
